package lwjglbase;

import java.nio.FloatBuffer;
import static org.lwjgl.opengl.GL11.*;
import org.newdawn.slick.opengl.InternalTextureLoader;
import org.newdawn.slick.opengl.Texture;

public class Sprite {
    static FloatBuffer verts;
    FloatBuffer texCoords;
    float x, y, xsize, ysize;
    public Texture tex;
    float depth = 0;

    void initTex(String input) {
        try {
            tex = InternalTextureLoader.get().getTexture(input, false, GL_LINEAR);
        } catch (Exception e) {
            e.printStackTrace();
        }
        float[] t = {0, 0, tex.getWidth(), 0, tex.getWidth(), tex.getHeight(), 0, tex.getHeight()};
        texCoords = Utils.createFB(t);
    }

    static void init() {
        float[] v = {0,0, 1,0, 1,1, 0,1};
        verts = Utils.createFB(v);
    }
    public void render() {
        glPushMatrix();
        tex.bind();
        glTranslatef(x, y, depth);
        glScalef(xsize,ysize,0);
        glVertexPointer(2, 0, verts);
        glTexCoordPointer(2, 0, texCoords);
        glDrawArrays(GL_QUADS, 0, 4);
        glPopMatrix();
    }
}
